package com.xxgc.cloud.consumer.springcloudconsumer.controller;

import com.xxgc.cloud.api.IHelloWorld;
import com.xxgc.cloud.api.IUserInfoService;
import com.xxgc.cloud.api.bean.Users;
import com.xxgc.cloud.api.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "测试接口")
@RestController
@RequestMapping("/hello")
public class HelloWorldController {

    @DubboReference(
            interfaceClass = IHelloWorld.class,
            version = "1.0.1",//服务版本，与服务提供者版本一致
            check = false,//启动时检测内容提供者是否存在
            //timeout = 10000,//服务方法调用超时时间(包含提供者内容处理时间)
            retries = 3,//调用失败后的重试次数 不包含第一次
            loadbalance = "roundrobin")
    private IHelloWorld helloWorld;

    @DubboReference(interfaceClass = IUserInfoService.class,version = "1.0.0",check = false)
    private IUserInfoService iis;

    @GetMapping("/gethello")
    public Result getHello(){
        System.out.println(11);
        String s = helloWorld.sayHello();
        return Result.success(s);
    }

    @GetMapping("/user/{id}")
    public Result<Users> getUsersByUserId(@PathVariable Integer id){
        Users userInfoById = iis.getUserInfoById(id);
        return Result.success(userInfoById);
    }

    @GetMapping("/test_info")
    @ApiOperation(value = "网关过滤器测试")
    public Result getTestInfo(){
        return Result.success("token校验成功，拿到数据了");
    }


    @RequiresPermissions("hello:shiroTest")
    @GetMapping("/shiroTest")
    @ApiOperation(value = "权限测试")
    public Result shiroTest(){
        return Result.success("权限认证通过，拿到数据了");
    }

    @RequiresPermissions("hello:shiroTest2")
    @GetMapping("/shiroTest2")
    @ApiOperation(value = "权限测试2")
    public Result shiroTest2(){
        return Result.success("权限认证通过拿到权限2");
    }
}
